home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / allfil.arc / GETFILE.LIB < prev    next >
Encoding:
Text File  |  1986-03-09  |  3.8 KB  |  116 lines

  1.   {@@@@@@@@@@@ copyright (C) 1984 by Neil J. Rubenking @@@@@@@@@@@@@@@@@@@@@@@@
  2.   The purchaser of these procedures and functions may include them in COMPILED
  3.   programs freely, but may not sell or give away the source text.
  4.  
  5.  
  6.   GETFILE consists of a set of three procedures based on a variable-type
  7.   BUFFER-TYPE, which is the exact "shape" of the information returned by
  8.   DOS function calls $4E (Find First matching file) and $4F (Find Next).
  9.  
  10.   SetDTA is called by Find_First to Set the Data Transfer Area to the Buffer.
  11.  
  12.   Find_First takes as input the file attribute and name-template of the file
  13.   required and returns the actual attribute found, the first matching name,
  14.   and an error code.
  15.  
  16.   Find_Next takes no input, but the buffer must be initialized by Find_First.
  17.   The output of Find_Next is the same as that of Find_First.
  18.  
  19.   Any program that calls GETFILE must also INCLUDE the standard type definitions
  20.   in FILENAME.TYP and REGPACK.TYP.
  21.  
  22.   The procedures of GETFILE are used by ALLFILES.LIB for a very handy file
  23.   selection module.}
  24.   {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
  25.  
  26. TYPE
  27.   buffer_type = RECORD
  28.                   reserved : ARRAY[1..21] OF Byte;
  29.                   attribute : Byte;
  30.                   time, date, FileSizeLo, FileSizeHi : Integer;
  31.                   name : STRING[13];
  32.                 END;
  33. VAR
  34.   filename : filename_type;   {NOTE that filename_type is declared in
  35.                               the file FILENAME.TYP.  This is in order
  36.                               to avoid multiple declarations}
  37.   buffer : buffer_type;
  38.   attribute : Byte;
  39.   {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  40.   PROCEDURE SetDTA(VAR buff);
  41.   VAR
  42.     registers : regpack;
  43.   BEGIN
  44.     WITH registers DO
  45.       BEGIN
  46.         AX := $1A SHL 8;
  47.         DS := Seg(buff);
  48.         DX := Ofs(buff);
  49.         MsDos(registers);
  50.       END;
  51.   END;
  52.   {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  53.   PROCEDURE Find_Next(VAR att : Byte; VAR filename : filename_type;
  54.                       VAR Next_error : Byte);
  55.   VAR
  56.     registers : regpack;
  57.     carry_flag : Integer;
  58.     N : Byte;
  59.   BEGIN
  60.     FillChar(buffer.name, SizeOf(buffer.name), 0);
  61.     WITH registers DO
  62.       BEGIN
  63.         AX := $4F SHL 8;
  64.         MsDos(registers);
  65.         att := buffer.attribute;
  66.         carry_flag := 1 AND Flags;
  67.         filename := '             ';
  68.         IF carry_flag = 1 THEN
  69.           Next_error := AX AND $00FF
  70.         ELSE
  71.           BEGIN
  72.             Next_error := 0;
  73.             FOR N := 0 TO 12 DO FileName[N+1] := buffer.name[N];
  74.           END;
  75.       END;                    {with}
  76.     att := buffer.attribute;
  77.   END;
  78.   {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  79.   PROCEDURE Find_First(VAR att : Byte;
  80.                        VAR filename : filename_type;
  81.                        VAR error_code : Byte);
  82.  
  83.   VAR
  84.     registers : regpack;
  85.     carry_flag : Integer;
  86.     mask, N : Byte;
  87.  
  88.   BEGIN
  89.     SetDTA(buffer);
  90.     filename[Length(filename)+1] := Chr(0);
  91.     FillChar(buffer.name, SizeOf(buffer.name), 0);
  92.     WITH registers DO
  93.       BEGIN
  94.         AX := $4E SHL 8;
  95.         CX := att;
  96.         DS := Seg(filename);
  97.         DX := Ofs(filename)+1;
  98.         MsDos(registers);
  99.         att := buffer.attribute;
  100.         { If there was an error set the error code and don't do
  101.         anything else. }
  102.  
  103.         carry_flag := 1 AND Flags;
  104.         IF carry_flag = 1 THEN
  105.           BEGIN
  106.             error_code := AX AND $00FF;
  107.           END
  108.         ELSE
  109.           BEGIN
  110.             error_code := 0;
  111.             filename := '             ';
  112.             FOR N := 0 TO 12 DO FileName[N+1] := buffer.name[N];
  113.           END;
  114.       END;                    {with}
  115.   END;
  116.